package com.mo.modular.tv.utils.tool;

import org.apache.commons.lang.StringUtils;

public class CheckBlackAndUsersFromGids {

	public static int checkUserGids(String contGids, String userGids) {
		if (StringUtils.isBlank(contGids)) {
			return 1;
		}
		if (StringUtils.isBlank(userGids)) {
			return 0;
		}

		String[] _contGids = contGids.split(",");
		if (_contGids.length == 1) {
			return StringUtils.contains(userGids, ","+contGids+",") ? 1 : 0;
		}

		String[] _userGids = userGids.split(",");
		if (_userGids.length == 1) {
			return StringUtils.contains(contGids, ","+userGids+",") ? 1 : 0;
		}

		for (String id : _contGids) {
			if (StringUtils.contains(userGids, ","+id+","))
				return 1;
		}
		return 0;
	}
	
	public static int checkBlackGids(String contGids, String userGids) {
		if (StringUtils.isBlank(contGids) || StringUtils.isBlank(userGids)) {
			return 0;
		}

		String[] _contGids = contGids.split(",");
		if (_contGids.length == 1) {
			return StringUtils.contains(userGids, ","+contGids+",") ? 1 : 0;
		}
		String[] _userGids = userGids.split(",");
		if (_userGids.length == 1) {
			return StringUtils.contains(contGids, ","+userGids+",") ? 1 : 0;
		}

		for (String id : _contGids) {
			if (StringUtils.contains(userGids, ","+id+","))
				return 1;
		}
		return 0;
	}
	
	public static int compareVersion(String version1, String version2) {
		System.out.println(version1+"================="+version2);
		if (version1.equals(version2)) {
        return 0;
		    }
		if(version1==null||"".equals(version1)){
			return 0;
		}
		     String[] version1Array = version1.split("\\.");
		      String[] version2Array = version2.split("\\.");
		      int index = 0;
		      //获取最小长度值
		      int minLen = Math.min(version1Array.length, version2Array.length);
		     int diff = 0;
		     //循环判断每位的大小
		     while (index < minLen && (diff = Integer.parseInt(version1Array[index]) - Integer.parseInt(version2Array[index])) == 0) {
		        index++;
		     }
		     if (diff == 0) {
		         //如果位数不一致，比较多余位数
		        for (int i = index; i < version1Array.length; i++) {
		             if (Integer.parseInt(version1Array[i]) > 0) {
		                return 1;
		             }
		         }
		
		       for (int i = index; i < version2Array.length; i++) {
		             if (Integer.parseInt(version2Array[i]) > 0) {
		                 return -1;
		             }
		         }
		         return 0;
		     } else {
		         return diff > 0 ? 1 : -1;
		     }
		 }
}
